package cn.ming.wfchat.app.me.fragemt;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.AppService;
import cn.ming.wfchat.app.dialog.ExchangeFjListDialog;
import cn.ming.wfchat.app.me.activity.ExchangeActivity;
import cn.ming.wfchat.app.me.activity.model.AssetsBean;
import cn.wildfirechat.remote.ChatManager;

/**
 * @author luoming
 * created at 2019-10-14 10:32
 * 币种FJ
 */
public class CurrencyFjFragemt extends Fragment {
    @BindView(R.id.tv_usdtRate)
    TextView tvUsdtRate;
    @BindView(R.id.tv_usdtRate_text)
    TextView tvUsdtRateText;
    @BindView(R.id.tv_balance)
    TextView tvBalance;
    @BindView(R.id.tv_frozenBalance)
    TextView tvFrozenBalance;
    @BindView(R.id.ll_layout)
    LinearLayout llLayout;
    @BindView(R.id.tv_sumBalance)
    TextView tvSumBalance;
    private AssetsBean.ListBean assetsB;

    public static CurrencyFjFragemt newInstance() {
        CurrencyFjFragemt situationFragemt = new CurrencyFjFragemt();
        Bundle bundle = new Bundle();
        // bundle.putParcelable("data", dataBean);
        situationFragemt.setArguments(bundle);
        return situationFragemt;
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.currency_fj_fragemt, container, false);
        ButterKnife.bind(this, view);
        ShowData();
        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }


    public void ShowData() {
        llLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                exchangeFjList();
            }
        });
        AppService.Instance().findMyAssets2(new AppService.AssetsCCallback() {
            @Override
            public void onUiSuccess(AssetsBean assetsBean) {
                assetsB = assetsBean.getList().get(0);
                tvUsdtRateText.setText("实时指数：FJ/CNY = " + assetsB.getRate());
                tvBalance.setText("可用：" + assetsB.getMainBalance() + "FJ");
                tvFrozenBalance.setText("实时指数：" + assetsB.getRate() + "    估值：" + assetsB.getValuationBanlance().toPlainString());
                tvUsdtRate.setText("≈" + assetsBean.getSumAmount().toPlainString() + "CNY");
                tvSumBalance.setText(assetsB.getMainBalance() + "FJ");
            }

            @Override
            public void onUiFailure(int code, String msg) {
                ChatManager.showToast(msg);

            }
        });

    }

    private void exchangeFjList() {
        Intent intent = new Intent(getActivity(), ExchangeActivity.class);

        ExchangeFjListDialog.newInstance().setOnClickListener(new ExchangeFjListDialog.OnClickListener() {
            @Override
            public void erc() {
                intent.putExtra("coinType","ETH_USDT");
                getActivity().startActivity(intent);
            }

            @Override
            public void trc() {
                intent.putExtra("coinType","TRX_USDT");
                getActivity().startActivity(intent);
            }
        }).show(getActivity());
    }

}
